#ifndef SINGLERUN_H
#define SINGLERUN_H

#if defined(Q_OS_WIN)
#include <Windows.h>
#elif defined(Q_OS_MACOS)
#elif defined(Q_OS_LINUX)
#endif

class SingleRun
{
public:
    SingleRun(const char *mutexName) : alreadyRun(false)
    {
#if defined(Q_OS_WIN)
        mutex = nullptr;

        mutex = CreateMutexA(NULL, FALSE, mutexName);
        if (GetLastError() == ERROR_ALREADY_EXISTS)
        {
            alreadyRun = true;
        }
#endif
    }

    ~SingleRun(void)
    {
#if defined(Q_OS_WIN)
        if (mutex != nullptr)
        {
            CloseHandle(mutex);
            mutex = NULL;
        }
#endif
    }

    inline bool isAlreadyRun() const
    {
        return alreadyRun;
    }

private:
#if defined(Q_OS_WIN)
    HANDLE mutex;
#endif

    bool alreadyRun;
};

#endif // SINGLERUN_H
